package com.villaday.idf.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.villaday.idf.R;

import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.model2.Presell_list;
import com.villaday.idf.model3.DataEntity;
import com.villaday.idf.model3.HashOrdersEntity;
import com.villaday.idf.util.ImageViewUtils;
import com.villaday.idf.util.PhoneUtil;

public class ShopAdapter extends AbsRecyclerViewAdapter<HashOrdersEntity.BodyBean.ListBean> {

    View.OnClickListener onClickListener;

    public ShopAdapter(Context context, View.OnClickListener onClickListener) {
        super(context, R.layout.recycle_shop, R.layout.item_page_loading);
        this.onClickListener = onClickListener;
    }

    @Override
    public int getItemType(HashOrdersEntity.BodyBean.ListBean d) {
        return d.getMyType();
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, HashOrdersEntity.BodyBean.ListBean d, int position) {
        try {
            switch (d.getMyType()) {
                case 0:
                    holder.bindTextView(R.id.tv_s_name, d.getCustomer().getName())
                            .bindTextView(R.id.tv_s_addr, d.getProduct().getName())
                            .bindTextView(R.id.tv_s_money, Html.fromHtml(" &yen;") + d.getCostPrice())
                            .bindTextView(R.id.tv_s_time, d.getCheckInDateTime() + "\n" + d.getCheckOutDateTime())
                            .bindTextView(R.id.tv_shop_type, d.getState().getText());


                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_s_time), true);
                    PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_s_money), true);

                    TextView tvType = (TextView) holder.getView(R.id.tv_shop_type);
                    ImageView ivType = (ImageView) holder.getView(R.id.iv_shop_type);


                    if (d.getState().getText().equals("待确认") || d.getState().getText().equals("确认中")) {
                        tvType.setTextColor(context.getResources().getColor(R.color.color5495E2));
                        ivType.setImageResource(R.drawable.ic_shop_right_blue);
                    } else if (d.getState().getText().equals("待入住") || d.getState().getText().equals("待使用")) {
                        tvType.setTextColor(context.getResources().getColor(R.color.color03C07C));
                        ivType.setImageResource(R.drawable.ic_shop_right_green);
                    } else if (d.getState().getText().equals("待结算") || d.getState().getText().equals("已完成")) {
                        tvType.setTextColor(context.getResources().getColor(R.color.colorFD4C4D));
                        ImageViewUtils.setImageViewColor(ivType, Color.argb(255, 255, 76, 77));
                    } else {
                        tvType.setTextColor(context.getResources().getColor(R.color.color5495E2));
                        ivType.setImageResource(R.drawable.ic_shop_right_blue);
                    }

                    if ((position + 1) % 2 != 1) {
                        holder.getView(R.id.ll_shop).setBackgroundResource(R.color.colorBackground);
                    } else {
                        holder.getView(R.id.ll_shop).setBackgroundResource(R.color.colorWhite);
                    }
                    holder.getView(R.id.ll_shop_type).setTag(position);
                    holder.getView(R.id.ll_shop_type).setOnClickListener(onClickListener);

                    if (position == (data.size() - 1)) {
                        holder.getView(R.id.vw_bottom_line).setVisibility(View.VISIBLE);
                        holder.getView(R.id.vw_bottom).setVisibility(View.VISIBLE);
                    } else {
                        holder.getView(R.id.vw_bottom_line).setVisibility(View.GONE);
                        holder.getView(R.id.vw_bottom).setVisibility(View.GONE);
                    }

                    break;
                case 1:
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
